Imports System.Threading

Public Class ErrorHandler

#Region "Properties"

	Private Shared _Count As Integer = 0

	Public Shared ReadOnly Property Count() As Integer
		Get
			Return _Count
		End Get
	End Property

#End Region

#Region "Error handlers"

	Public Shared Function Handle(ByVal ex As Exception) As String

		Return Handle(ex, String.Empty)

	End Function

	Public Shared Function Handle(ByVal ex As Exception, ByVal strCustomMessage As String) As String

		Dim objHandle As Handler

		If ex.GetType() Is GetType(ErrooException) Then
			Return "ErrooException"
		End If

		_Count += 1

		If strCustomMessage Is Nothing OrElse strCustomMessage = String.Empty Then
			strCustomMessage = My.Resources.Messages.DefaultErrorMessage
		End If

		objHandle = New Handler(New ExceptionInfo(ex, strCustomMessage), Config.DoEventLog, Config.DoFileLog)

		Return objHandle.Exception.HTML

	End Function

	Public Shared Sub OnThreadException(ByVal sender As Object, ByVal t As ThreadExceptionEventArgs)

		Try
			Handle(t.Exception)
		Catch
			' Oh shit!!!!!!!!
		End Try

	End Sub

#End Region

End Class